<template>
  <el-skeleton :loading="loading" animated>
    <template #template>
      <div>
        <el-skeleton-item
          variant="image"
          style="width: 400px; height: 267px; float: left"
        />
        <div style="padding: 14px; float: left">
          <el-skeleton-item variant="h3" style="width: 50%" />
          <div
            style="
              display: flex;
              align-items: center;
              justify-items: space-between;
              margin-top: 16px;
              height: 16px;
              width: 500px;
            "
          ></div>
          <el-skeleton :rows="5" />
        </div>
      </div>
    </template>
    <template #default>
      <div>
        <el-row>
          <el-col :span="6">
            <div class="box-left grid-content bg-purple">
              <img :src="playlist.coverImgUrl" alt="" />
            </div>
          </el-col>
          <el-col :span="16">
            <div class="grid-content bg-purple hei">
              <div class="top-1">
                <span>歌单</span>
                <h2>{{ playlist.name }}</h2>
              </div>
              <div class="top-2">
                <img :src="playlist.creator.avatarUrl" alt="" />
                <div>
                  <span>{{
                    playlist.creator.signature
                      ? playlist.creator.signature
                      : "无简介"
                  }}</span>
                  <span>{{ time(playlist.createTime) }}</span>
                </div>
              </div>
              <div class="top-3">
                <el-button @click="Bo" type="danger">播放全部</el-button>
              </div>
              <div class="box-bottom">
                标签：<span
                  class="box-bottom"
                  v-for="Tags in playlist.tags"
                  :key="Tags"
                  >{{ Tags }}</span
                >
              </div>

              <div class="box-bottom">
                歌曲数量: {{ length ?? "0" }} 播放:
                {{ changCount(playlist.playCount) ?? "暂时没人有播放" }}
              </div>
              <div ref="box" class="box-bottom Jia">
                简介：{{ playlist.description ?? "这个人太懒了什么也没写" }}
              </div>
              <Tt class="butt" :description="playlist.description" />
            </div>
          </el-col>
        </el-row>
      </div>
    </template>
  </el-skeleton>
</template>


<script>
import { More } from "@element-plus/icons-vue";
import { mapState, mapMutations } from "vuex";
import { getCurrentInstance, onMounted } from "vue";
import Tt from "./t.vue";

export default {
  data() {
    return {
      loading: true,
    };
  },
  props: ["playlist", "itemList", "length"],
  setup(props) {
    if ((props.playlist.creator = "")) {
      props.playlist.creator = JSON.parse(
        sessionStorage.getItem().playlist
      ).creator;
    }
  },
  methods: {
    changCount: function (num) {
      if (num >= 100000000) {
        return (num / 100000000).toFixed(1) + "亿";
      } else if (num < 100000000 && num >= 100000) {
        return (num / 100000).toFixed(1) + "万";
      }
    },
    time: function (tt) {
      var time = new Date(tt);
      var times = time.toLocaleDateString().replace(/\//g, "-");
      return times + " 创建";
    },
    Bo: function () {
      this.updatePlayList(this.itemList);
      this.upDatePlayListIndex(0);
    },
    ...mapMutations(["upDatePlayListIndex", "updatePlayList"]),
  },
  components: {
    More,
    Tt,
  },
  watch: {
    playlist: function (to) {
      this.loading = false;
    },
  },
};
</script>

<style lang="less" scoped>
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
}
.box-left {
  height: 230px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
  img {
    width: 100%;
  }
}
.top-1 {
  margin-bottom: 10px;
  span {
    display: inline-block;
    height: 23px;
    width: 42px;
    line-height: 23px;
    text-align: center;
    color: #fd544d;
    border: 1px solid #fd544d;
    border-radius: 5px;
    margin: 0 10px;
  }
  h2 {
    display: inline-block;
    margin: 0;
  }
}
.top-2 {
  padding-left: 10px;
  display: flex;
  flex-direction: center;
  margin-bottom: 5px;
  img {
    height: 34px;
    width: 34px;
    border-radius: 50%;
  }
  span {
    display: block;
    line-height: 17px;
    font-size: 12px;
    color: #000000;
    margin: 0 5px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
.top-3 {
  padding-left: 10px;
  .el-button {
    height: 36px;
    border-radius: 20px;
    margin: 5px 0;
    background-color: #fd544d;
    &:active {
      background-color: #cf2d28;
    }
  }
}
.box-bottom {
  padding-left: 10px;
  font-size: 14px;
  color: #000000;
  margin: 5px 0;
}
.Jia {
  height: 59px;
  width: 600px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hei {
  height: 240px;
}
.butt {
  float: right;
}
</style>
